#include "MarsPrecompile.h"

#include "MarsEngine.h"
#include "MarsPipelineMgr.h"
#include "MarsRenderer.h"
#include "MarsConstantMgr.h"
#include "MarsMeshMgr.h"
#include "MarsSceneMgr.h"

using namespace Core;
using namespace SceneGraph;
using namespace Graphics;

Engine* Engine::ms_pEngine = 0;

void Engine::Destroy()
{
	SAFE_DELETE( ms_pEngine );
}

Engine::Engine()
{

}

Engine::~Engine()
{
	Shutdown();
}

bool Engine::Initialize( HINSTANCE hInstance, HWND hwnd )
{
	if ( !Renderer::Instance().Initialize( hInstance, hwnd ) )
	{
		Shutdown();
		return false;
	}

	if ( !ConstantMgr::Instance().Initialize() )
	{
		Shutdown();
		return false;
	}

	if ( !PipelineMgr::Instance().Initialize() )
	{
		Shutdown();
		return false;
	}

	if ( !MeshMgr::Instance().Initialize() )
	{
		Shutdown();
		return false;
	}

	if ( !SceneMgr::Instance().Initialize() )
	{
		Shutdown();
		return false;
	}

	return true;
}

void Engine::Shutdown()
{
	SceneMgr::Destroy();
	MeshMgr::Destroy();
	PipelineMgr::Destroy();
	ConstantMgr::Destroy();
	Renderer::Destroy();
}
